package com.eco.fanliapp.shengyaappeurekeclient.service.Impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eco.fanliapp.shengyaappeurekeclient.dao.AppGoodsMapper;
import com.eco.fanliapp.shengyaappeurekeclient.entity.AppGoods;
import com.eco.fanliapp.shengyaappeurekeclient.entity.vo.AppGoodsVo;
import com.eco.fanliapp.shengyaappeurekeclient.service.IAppGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Service
public class IAppGoodsServiceImpl extends ServiceImpl<AppGoodsMapper, AppGoods> implements IAppGoodsService {



    @Autowired
    private RestTemplate restTemplate;

    @Override
    public Object getPrice(Long userId, List<AppGoods> appGoods) {
        try {
            String goods = JSONObject.toJSONString(appGoods);
            String data = restTemplate.postForObject("http://service-appserver" + "/mobile/home/getGoodsScheme?userId=" + userId + "&keyword=" + null, goods, String.class);
            data = JSONObject.parseObject(data).getString("data");
            List<AppGoodsVo> list = null;
            if (data != null || data != "") {
                list = JSONObject.parseArray(data, AppGoodsVo.class);
                if (list != null && list.size() > 0) {
                    return list.get(0).getTheirPriceMoney();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
